package com.king.collect;


import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

import java.util.Collection;

/**
 * Created by Administrator on 2015/4/23.
 */
public class MulitMapDemo {
    public static void main(String[] args) {
        Multimap<String,String> multimap = ArrayListMultimap.create();

        multimap.put("Fruits", "Bannana");
        multimap.put("Fruits", "Apple");
        multimap.put("Fruits", "Pear");
        multimap.put("Vegetables", "Carrot");


        int size = multimap.size();
        System.out.println("multimap的size是:"+size);


        Collection<String> fruits = multimap.get("Fruits");
        System.out.println("所有的水果："+fruits);

        Collection<String> vegetables = multimap.get("Vegetables");
        System.out.println("所有的蔬菜是:"+vegetables);


        for(String value : multimap.values()) {
            System.out.println("获取全部的multimap:"+value);
        }


        multimap.remove("Fruits","Pear");
        System.out.println("移除梨："+multimap.get("Fruits"));


        multimap.removeAll("Fruits");
        System.out.println("去除所有的水果:"+ multimap.get("Fruits"));
    }
}

